package com.digitalchina.lxnsy.xml;

import android.content.Context;

import com.digitalchina.lxnsy.entity.PersonalInfoVO;
import com.digitalchina.lxnsy.toolkit.SharedPreferencesUtil;

import java.util.List;


/**
 * ================================================
 * 项目名称：bigdata
 * 类描述：
 * 包名：com.digitalchina.bigdata.xml
 * 创建人：郑皓
 * 创建时间：2016/6/1 14:24
 * 修改备注：
 * ================================================
 */
public class PersonalInfoXML {


    public static final String XML_NAME_PERSONAL_INFO = "PersonalInfo";


    private static final String ID = "id";
    private static final String USERACCID = "userAccId"; // 用户ID
    private static final String USERNAME = "userName";   // 用户名
    private static final String NICENAME = "niceName";   // 昵称
    private static final String HEADPORTRAIT = "headPortrait";   // 头像
    private static final String TRUENAME = "trueName";   // 真实姓名
    private static final String USERSEX = "userSex";   // 性别 1-男  0-女
    private static final String USERBIRTHDAY = "userBirthday";   // 生日
    private static final String IDCARDNO = "idCardNo";   // 身份证号
    private static final String EDUCATIONCODE = "educationCode";   // 学历code
    private static final String MOBILEPHONE = "mobilePhone"; // 电话号码
    private static final String USEREMAIL = "userEmail"; // 电子邮件
    private static final String DIMENSIONS = "dimensions";   // 规模
    private static final String USERTYPE = "userType";   // 用户类型
    private static final String ADDRESS = "address";   // 所在区域
    private static final String INDUSTRY = "industry";   // 产业拼接1-2级Name

    private static final String HOBBIES_NAME = "hobbiesName";   // 兴趣爱好NAME
    private static final String HOBBIES_CODE = "hobbiesCode";   // 兴趣爱好code
    private static final String HOBBIES_JSON = "HobbiesJson";   // 兴趣爱好json<全部>

    private static final String FIRSTINDUSTRYCODE = "firstIndustryCode";   // 产业1级code
    private static final String FIRSTINDUSTRYNAME = "firstIndustryName";   // 产业1级name
    private static final String INDUSTRYCODE = "industryCode";   // 产业2级code
    private static final String INDUSTRYNAME = "industryName";   // 产业2级name

    private static final String PROVINCECODE = "provinceCode";   // 省编码
    private static final String CITYCODE = "cityCode";   // 市编码
    private static final String COUNTYCODE = "countyCode";   // 区编码
    private static final String GOMYEXPERT = "goMyExpert";   // 是否进入我的专家


    /**
     * 储存个人信息
     *
     * @param ctx
     * @param personalInfoVO
     */
    public static void setPersonalInfoVO(Context ctx, PersonalInfoVO personalInfoVO) {
        setValue(ctx, ID, personalInfoVO.getId());
        setValue(ctx, USERACCID, personalInfoVO.getUserAccId());
        setValue(ctx, USERNAME, personalInfoVO.getUserName());
        setValue(ctx, NICENAME, personalInfoVO.getNiceName());
        setValue(ctx, HEADPORTRAIT, personalInfoVO.getHeadPortrait());
        setValue(ctx, TRUENAME, personalInfoVO.getTrueName());
        setValue(ctx, USERSEX, personalInfoVO.getUserSex());
        setValue(ctx, USERBIRTHDAY, personalInfoVO.getUserBirthday());
        setValue(ctx, IDCARDNO, personalInfoVO.getIdCardNo());
        if (personalInfoVO.getEducation() != null)
            setValue(ctx, EDUCATIONCODE, personalInfoVO.getEducation().getCode());
        setValue(ctx, MOBILEPHONE, personalInfoVO.getMobilePhone());
        setValue(ctx, USEREMAIL, personalInfoVO.getUserEmail());
        setValue(ctx, DIMENSIONS, personalInfoVO.getDimensions());
        setValue(ctx, USERTYPE, personalInfoVO.getUserType());

        setValue(ctx, INDUSTRY, personalInfoVO.getFirstIndustryName() + " " + personalInfoVO.getIndustryName());
        if (personalInfoVO.getProvince() != null && personalInfoVO.getCity() != null && personalInfoVO.getCounty() != null) {

            if (personalInfoVO.getProvince().equals("110000") || personalInfoVO.getProvince().equals("120000") || personalInfoVO.getProvince().equals("310000") || personalInfoVO.getProvince().equals("500000")
                    || (personalInfoVO.getProvince().equals("460000") && personalInfoVO.getCity().equals("469000"))) {
                setValue(ctx, ADDRESS, String.format("%s %s", personalInfoVO.getProvince().getName(), personalInfoVO.getCounty().getName()));
            } else {
                setValue(ctx, ADDRESS, String.format("%s %s %s", personalInfoVO.getProvince().getName(), personalInfoVO.getCity().getName(), personalInfoVO.getCounty().getName()));
            }
        }
        setValue(ctx, FIRSTINDUSTRYCODE, personalInfoVO.getFirstIndustryCode());
        setValue(ctx, FIRSTINDUSTRYNAME, personalInfoVO.getFirstIndustryName());
        setValue(ctx, INDUSTRYCODE, personalInfoVO.getIndustryCode());
        setValue(ctx, INDUSTRYNAME, personalInfoVO.getIndustryName());

        if (personalInfoVO.getProvince() != null)
            setValue(ctx, PROVINCECODE, personalInfoVO.getProvince().getCode());
        if (personalInfoVO.getCity() != null)
            setValue(ctx, CITYCODE, personalInfoVO.getCity().getCode());
        if (personalInfoVO.getCounty() != null)
            setValue(ctx, COUNTYCODE, personalInfoVO.getCounty().getCode());

        // 存入已选中兴趣爱好name code
        setValue(ctx, HOBBIES_NAME, getHobbiesName(personalInfoVO.getHobbies()));
        setValue(ctx, HOBBIES_CODE, getHobbiesCode(personalInfoVO.getHobbies()));
    }


    /**
     * 获取兴趣爱好List 返回字符串集合
     *
     * @param hobbiesBeen
     * @return
     */
    private static String getHobbiesName(List<PersonalInfoVO.HobbiesBean> hobbiesBeen) {
        String hobbiesName = "";

        if (hobbiesBeen != null && hobbiesBeen.size() > 0)
            for (int i = 0; i < hobbiesBeen.size(); i++)
                hobbiesName += hobbiesBeen.get(i).getHobbyName() + ";";

        return hobbiesName;
    }


    /**
     * 获取兴趣爱好Code 以分号隔开
     *
     * @param hobbiesBeen
     * @return
     */
    private static String getHobbiesCode(List<PersonalInfoVO.HobbiesBean> hobbiesBeen) {
        String hobbiesCode = "";
        if (hobbiesBeen != null && hobbiesBeen.size() > 0)
            for (int i = 0; i < hobbiesBeen.size(); i++)
                hobbiesCode += hobbiesBeen.get(i).getHobbyCode() + ";";

        return hobbiesCode;
    }

    private static void setValue(Context ctx, String psKey, String psValue) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_PERSONAL_INFO, psKey, psValue);
    }

    /**
     * 设置头像fileName
     *
     * @param ctx
     * @param value
     */
    public static void setHeadportrait(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_PERSONAL_INFO, HEADPORTRAIT, value);
    }

    /**
     * 获取头像fileName
     *
     * @param ctx
     * @return
     */
    public static String getHeadportrait(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_PERSONAL_INFO, HEADPORTRAIT, "");
    }

    /**
     * 设置HobbiesJson
     *
     * @param ctx
     * @param value
     */
    public static void setAllHobbiesJson(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_PERSONAL_INFO, HOBBIES_JSON, value);
    }

    /**
     * 获取HobbiesJson
     *
     * @param ctx
     * @return
     */
    public static String getAllHobbiesJson(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_PERSONAL_INFO, HOBBIES_JSON, "");
    }

    /**
     * 设置用户名  (一般不会主动使用)
     *
     * @param ctx
     * @param value
     */
    public static void setUserName(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_PERSONAL_INFO, USERNAME, value);
    }

    /**
     * 获取用户名
     *
     * @param ctx
     * @return
     */
    public static String getUserName(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_PERSONAL_INFO, USERNAME, "");
    }

    /**
     * 设置昵称
     *
     * @param ctx
     * @param value
     */
    public static void setNiceName(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_PERSONAL_INFO, NICENAME, value);
    }

    /**
     * 获取昵称
     *
     * @param ctx
     * @return
     */
    public static String getNiceName(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_PERSONAL_INFO, NICENAME, "");
    }

    /**
     * 设置性别
     *
     * @param ctx
     * @param value
     */
    public static void setUserSex(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_PERSONAL_INFO, USERSEX, value);
    }

    /**
     * 获取性别
     *
     * @param ctx
     * @return
     */
    public static String getUserSex(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_PERSONAL_INFO, USERSEX, "");
    }

    /**
     * 设置生日
     *
     * @param ctx
     * @param value
     */
    public static void setUserBirthday(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_PERSONAL_INFO, USERBIRTHDAY, value);
    }

    /**
     * 获取生日
     *
     * @param ctx
     * @return
     */
    public static String getUserBirthday(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_PERSONAL_INFO, USERBIRTHDAY, "");
    }

    /**
     * 设置E-MAIL
     *
     * @param ctx
     * @param value
     */
    public static void setUserEmail(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_PERSONAL_INFO, USEREMAIL, value);
    }

    /**
     * 获取E-MAIL
     *
     * @param ctx
     * @return
     */
    public static String getUserEmail(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_PERSONAL_INFO, USEREMAIL, "");
    }

    /**
     * 设置规模
     *
     * @param ctx
     * @param value
     */
    public static void setDimensions(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_PERSONAL_INFO, DIMENSIONS, value);
    }

    /**
     * 获取规模
     *
     * @param ctx
     * @return
     */
    public static String getDimensions(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_PERSONAL_INFO, DIMENSIONS, "");
    }

    /**
     * 设置手机号码
     *
     * @param ctx
     * @param value
     */
    public static void setMobilePhone(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_PERSONAL_INFO, MOBILEPHONE, value);
    }

    /**
     * 获取手机号码
     *
     * @param ctx
     * @return
     */
    public static String getMobilePhone(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_PERSONAL_INFO, MOBILEPHONE, "");
    }

    /**
     * 设置地址
     *
     * @param ctx
     * @param value
     */
    public static void setAddress(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_PERSONAL_INFO, ADDRESS, value);
    }

    /**
     * 获取地址
     *
     * @param ctx
     * @return
     */
    public static String getAddress(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_PERSONAL_INFO, ADDRESS, "");
    }

    /**
     * 设置1级产业code
     *
     * @param ctx
     * @param value
     */
    public static void setFirstIndustryCode(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_PERSONAL_INFO, FIRSTINDUSTRYCODE, value);
    }

    /**
     * 获取1级产业code
     *
     * @param ctx
     * @return
     */
    public static String getFirstIndustryCode(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_PERSONAL_INFO, FIRSTINDUSTRYCODE, "");
    }

    /**
     * 设置1级产业name
     *
     * @param ctx
     * @param value
     */
    public static void setFirstIndustryName(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_PERSONAL_INFO, FIRSTINDUSTRYNAME, value);
    }

    /**
     * 获取1级产业name
     *
     * @param ctx
     * @return
     */
    public static String getFirstIndustryName(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_PERSONAL_INFO, FIRSTINDUSTRYNAME, "");
    }

    /**
     * 设置2级产业code
     *
     * @param ctx
     * @param value
     */
    public static void setIndustryCode(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_PERSONAL_INFO, INDUSTRYCODE, value);
    }

    /**
     * 获取2级产业code
     *
     * @param ctx
     * @return
     */
    public static String getIndustryCode(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_PERSONAL_INFO, INDUSTRYCODE, "");
    }

    /**
     * 设置2级产业name
     *
     * @param ctx
     * @param value
     */
    public static void setIndustryName(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_PERSONAL_INFO, INDUSTRYNAME, value);
    }

    /**
     * 获取2级产业name
     *
     * @param ctx
     * @return
     */
    public static String getIndustryName(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_PERSONAL_INFO, INDUSTRYNAME, "");
    }

    /**
     * 设置产业1-2级name
     *
     * @param ctx
     * @param value
     */
    public static void setIndustry(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_PERSONAL_INFO, INDUSTRY, value);
    }

    /**
     * 获取产业1-2级name
     *
     * @param ctx
     * @return
     */
    public static String getIndustry(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_PERSONAL_INFO, INDUSTRY, "");
    }

    /**
     * 设置兴趣爱好name
     *
     * @param ctx
     * @param value
     */
    public static void setHobbiesName(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_PERSONAL_INFO, HOBBIES_NAME, value);
    }

    /**
     * 获取兴趣爱好name
     *
     * @param ctx
     * @return
     */
    public static String getHobbiesName(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_PERSONAL_INFO, HOBBIES_NAME, "");
    }

    /**
     * 设置兴趣爱好code
     *
     * @param ctx
     * @param value
     */
    public static void setHobbiesCode(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_PERSONAL_INFO, HOBBIES_CODE, value);
    }

    /**
     * 获取兴趣爱好code
     *
     * @param ctx
     * @return
     */
    public static String getHobbiesCode(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_PERSONAL_INFO, HOBBIES_CODE, "");
    }

    /**
     * 设置真实姓名
     *
     * @param ctx
     * @param value
     */
    public static void setTrueName(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_PERSONAL_INFO, TRUENAME, value);
    }

    /**
     * 获取真实姓名
     *
     * @param ctx
     * @return
     */
    public static String getTrueName(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_PERSONAL_INFO, TRUENAME, "");
    }

    /**
     * 设置身份证号
     *
     * @param ctx
     * @param value
     */
    public static void setIdCardNO(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_PERSONAL_INFO, IDCARDNO, value);
    }

    /**
     * 获取身份证号
     *
     * @param ctx
     * @return
     */
    public static String getIdCardNO(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_PERSONAL_INFO, IDCARDNO, "");
    }

    /**
     * 设置学历code
     *
     * @param ctx
     * @param value
     */
    public static void setEducationCode(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_PERSONAL_INFO, EDUCATIONCODE, value);
    }

    /**
     * 获取学历code
     *
     * @param ctx
     * @return
     */
    public static String getEducationCode(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_PERSONAL_INFO, EDUCATIONCODE, "");
    }


    /**
     * 设置省code
     *
     * @param ctx
     * @param value
     */
    public static void setProvinceCode(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_PERSONAL_INFO, PROVINCECODE, value);
    }

    /**
     * 获取省code
     *
     * @param ctx
     * @return
     */
    public static String getProvinceCode(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_PERSONAL_INFO, PROVINCECODE, "");
    }

    /**
     * 设置市code
     *
     * @param ctx
     * @param value
     */
    public static void setCityCode(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_PERSONAL_INFO, CITYCODE, value);
    }

    /**
     * 获取市code
     *
     * @param ctx
     * @return
     */
    public static String getCityCode(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_PERSONAL_INFO, CITYCODE, "");
    }

    /**
     * 设置区code
     *
     * @param ctx
     * @param value
     */
    public static void setCountyCodeCode(Context ctx, String value) {
        SharedPreferencesUtil.setValue(ctx, XML_NAME_PERSONAL_INFO, COUNTYCODE, value);
    }

    /**
     * 获取区code
     *
     * @param ctx
     * @return
     */
    public static String getCountyCodeCode(Context ctx) {
        return SharedPreferencesUtil.getValue(ctx, XML_NAME_PERSONAL_INFO, COUNTYCODE, "");
    }

//    /**
//     * 设置是否进入过我的专家
//     *
//     * @param ctx
//     * @param value
//     */
//    public static void setGoMyExpert(Context ctx, String value) {
//        SharedPreferencesUtil.setValue(ctx, XML_NAME_PERSONAL_INFO, GOMYEXPERT, value);
//    }
//
//    /**
//     * 设置是否进入过我的专家
//     *
//     * @param ctx
//     * @return
//     */
//    public static String getGoMyExpert(Context ctx) {
//        return SharedPreferencesUtil.getValue(ctx, XML_NAME_PERSONAL_INFO, GOMYEXPERT, "");
//    }

}

